import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Swiper } from 'antd-mobile'
class Index extends Component {
  // 默认props
  static defaultProps = {
    height: 150,
  }
  render() {
    // 解构数据
    const { banners, height, onClick } = this.props
    return (
      <Swiper style={{ height }}>
        {
          banners.length > 0 && banners.map((v, i) => {
            return (
            <Swiper.Item key={i} onClick={ (e) => onClick && onClick(e)   }>
              <img src={ v.url || v } alt="" style={{ height, width: '100%' }}/>
            </Swiper.Item>
            )
          })
        }
      </Swiper>
    );
  }
}

// 验证props
Index.propTypes = {
  banners: PropTypes.array.isRequired,
  height: PropTypes.number
};


export default Index;
